package com.xiaol.springbootredis.common.wrapper;

import com.xiaol.springbootredis.common.wrapper.page.PageUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * User: chenshun131 <p />
 * Time: 18/6/18 12:21  <p />
 * Version: V1.0  <p />
 * Description: The class Page wrapper <p />
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class PageWrapper<T> extends Wrapper<T> {

    private static final long serialVersionUID = 666985064788933395L;

    private PageUtil pageUtil;

    /**
     * Instantiates a new Page wrapper
     */
    public PageWrapper() {
        super();
    }

    /**
     * Instantiates a new Page wrapper
     *
     * @param code
     *         the code
     * @param message
     *         the message
     */
    public PageWrapper(int code, String message) {
        super(code, message);
    }

    /**
     * Instantiates a new pageWrapper default code=200
     *
     * @param result
     *         the result
     * @param pageUtil
     *         the page util
     */
    public PageWrapper(T result, PageUtil pageUtil) {
        super();
        this.setResult(result);
        this.setPageUtil(pageUtil);
    }

    /**
     * Instantiates a new Page wrapper
     *
     * @param code
     *         the code
     * @param message
     *         the message
     * @param result
     *         the result
     * @param pageUtil
     *         the page util
     */
    PageWrapper(int code, String message, T result, PageUtil pageUtil) {
        super(code, message, result);
        this.pageUtil = pageUtil;
    }

    /**
     * Sets the 分页数据 , 返回自身的引用
     *
     * @param pageUtil
     *         the page util
     * @return the page wrapper
     */
    public PageWrapper<T> pageUtil(PageUtil pageUtil) {
        this.setPageUtil(pageUtil);
        return this;
    }

    /**
     * Sets the 结果数据 , 返回自身的引用
     *
     * @param result
     *         the result
     * @return the page wrapper
     */
    @Override
    public PageWrapper<T> result(T result) {
        super.setResult(result);
        return this;
    }

}
